page_gcsj = (state={},action)->
  switch action.type
    when 'GCSJ/GET_PILOT_LIST_START'
      debugger
      Object.assign {},state,
        pilot:
          list:state.pilot.list
          isLoading:true
          refreshing:false
          pageIndex:state.pilot.pageIndex
          completed:false
    when 'GCSJ/GET_PILOT_LIST_COMPLETED'
      debugger
      Object.assign {},state,
        pilot:
          list:state.pilot.list.concat(action.payload.list)
          isLoading:false
          refreshing:false
          pageIndex:if action.payload.list.length > 0 then state.pilot.pageIndex+1 else state.pilot.pageIndex
          completed:action.payload.list.length < 20
    when 'GCSJ/REFRESH_PILOT_LIST_START'
      Object.assign {},state,
        pilot:
          list:[]
          isLoading:false
          refreshing:true
          completed:false

    when 'GCSJ/REFRESH_PILOT_LIST_COMPLETED'
      Object.assign {},state,
        pilot:
          list:action.payload.list
          isLoading:false
          pageIndex:1
          refreshing:false
          lastFetchTime:action.payload.lastFetchTime
          completed:true

    when 'GCSJ/GET_CAR_LIST_START'
      Object.assign {},state,
        car:
          isLoading:true
          list:state.car.list
          refreshing:false
          pageIndex:state.car.pageIndex
          completed:false
    when 'GCSJ/GET_CAR_LIST_COMPLETED'
      debugger
      Object.assign {},state,
        car:
          list:state.car.list.concat(action.payload.list)
          isLoading:false
          pageIndex:if action.payload.list.length > 0 then state.car.pageIndex+1 else state.car.pageIndex
          completed:action.payload.list.length < 20
          refreshing:false
    when 'GCSJ/REFRESH_CAR_LIST_START'
      Object.assign {},state,
        car:
          list:[]
          isLoading:false
          refreshing:true
          completed:false
    when 'GCSJ/REFRESH_CAR_LIST_COMPLETED'
      Object.assign {},state,
        car:
          list:action.payload.list
          isLoading:false
          refreshing:false
          pageIndex:1
          lastFetchTime:action.payload.lastFetchTime
          completed:true

    else
      state

module.exports = page_gcsj
